<?php

use app\common\services\StaticServices;
use yii\helpers\Url;

?>

<?= Yii::$app->view->renderFile('@app/modules/admin/views/common/tab_user.php', ['tab' => 'set']) ?>
<div class="ui equal width grid">
  <div class="column">
    <div class="panel">
      <div class="panel-alone-content">
        <form class="ui form">
          <div class="field">
            <label>人员名称:</label>
            <input type="text" name="user-name" placeholder="不能少于3个字"
                   value="<?= isset($info['user_name']) ? $info['user_name'] : '' ?>">
          </div>
          <div class="field">
            <label>人员电话:</label>
            <input type="text" name="user-phone" placeholder=""
                   value="<?= isset($info['user_phone']) ? $info['user_phone'] : '' ?>">
          </div>
          <div class="field">
            <label>人员证件号:</label>
            <input type="text" name="user-ID" placeholder=""
                   value="<?= isset($info['user_ID']) ? $info['user_ID'] : '' ?>">
          </div>
          <div class="field">
            <label>人员属性:</label>
            <div class="ui selection dropdown _dropdown" tabindex="0">
              <input type="hidden" name="user-role"
                     <?php if (isset($info['user_role'])): ?>value="<?= $info['user_role'] ?>" <?php endif; ?>>
              <i class="dropdown icon"></i>
              <div class="<?php if (!isset($info['user_role'])): ?>default<?php endif; ?> text"><?= isset($info['user_role']) ? (StaticServices::getUserRole())[$info['user_role']] : '请选择类型' ?></div>
              <div class="menu transition hidden" tabindex="-1">
                <?php foreach ($userRole as $key => $item): ?>
                  <div class="item <?php if (isset($info['user_role']) == $key): ?>active selected<?php endif; ?> "
                       data-value="<?= $key ?>"><?= $item ?></div>
                <?php endforeach; ?>

              </div>
            </div>
          </div>
          <div class="field role_pid"
               <?php if (!isset($info['role_pid']) || $info['user_role'] != '4'): ?>style="display: none" <?php endif; ?> >
            <label>隶属人员(如果是总中介,不需要选择):</label>
            <div class="ui selection dropdown _dropdown" tabindex="0">
              <input type="hidden" name="role-pid"
                     <?php if (isset($info['role_pid'])): ?>value="<?= $info['role_pid'] ?>" <?php endif; ?>>
              <i class="dropdown icon"></i>
              <div class="<?php if (!isset($info['role_pid'])): ?>default<?php endif; ?> text">
                <?php if (isset($info['role_pid']) && $info['role_pid'] == 0 && $info['user_role'] != 4): ?>
                  <?= '请选择类型' ?>
                <?php elseif (isset($info['role_pid']) && $info['user_role'] == 4): ?>
                  <?= $info['user_name'] ?>
                <?php else: ?>
                  <?= isset($info['role_pid']) ? (StaticServices::getUserRolePid())[$info['role_pid']] : '请选择类型' ?>
                <?php endif; ?>

              </div>
              <div class="menu transition hidden" tabindex="-1">
                <?php foreach (StaticServices::getUserRolePid() as $key => $item): ?>
                  <div class="item <?php if (isset($info['role_pid']) == $key): ?>active selected<?php endif; ?> "
                       data-value="<?= $key ?>"><?= $item ?></div>
                <?php endforeach; ?>

              </div>
            </div>
          </div>

          <div class="field  goodImg">
            <label>人员图片</label>
            <div class="img_good">
              <?php if ($info): ?>
                <input type='hidden' id='user_img' value="<?= $info['user_img'] ?>">
                <img src="<?= $info['user_img'] ?>" alt="">
              <?php endif; ?>
            </div>
            <script type="text/plain" id="upload_ue"></script>
            <a href="javascript:void(0);" class="act_banner" style="background: rgb(255, 255, 255);">上传图片</a>
          </div>
          <div class="field">
            <label>人员简历:</label>
            <script id="user_editor"
                    type="text/plain"><?= isset($info['user_resume']) ? $info['user_resume'] : '' ?></script>
          </div>

          <input type="hidden" name="_csrf" id='csrf' value="<?= Yii::$app->request->csrfToken ?>">
          <input type="hidden" name="user-id" value="<?= isset($info['id']) ? $info['id'] : 0 ?>">
          <input type="hidden" name="user-role" value="<?= isset($info['user_role']) ? $info['user_role'] : 0 ?>">
          <button class="ui green basic button user-save  " type="button">提交</button>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
  UE.getEditor('user_editor', {
    toolbars: [
      ['undo', 'redo', '|',
        'bold', 'italic', 'underline', 'strikethrough', 'removeformat', 'formatmatch', 'autotypeset',
        'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist',
        'selectall', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight'
      ],
      ['customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
        'directionalityltr', 'directionalityrtl', 'indent', '|',
        'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
        'link', 'unlink', 'simpleupload'
      ],
      ['imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
        'horizontal', 'spechars', '|', 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow',
        'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells',
        'splittorows', 'splittocols'
      ]

    ],
    enableAutoSave: true,
    saveInterval: 60000,
    elementPathEnabled: false,
    initialFrameHeight: 400,
  });

  var _editor = UE.getEditor('upload_ue');
  _editor.ready(function () {
    //设置编辑器不可用
    //_editor.setDisabled();
    //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
    _editor.hide();
    //侦听图片上传
    _editor.addListener('beforeInsertImage', function (t, arg) {
      var banner = arg[0].src;
      //将地址赋值给相应的input,只去第一张图片的路径
      $('.goodImg').append("<input type='hidden' id='user_img' value='" + banner + "'>");
      $('.img_good').empty();
      var html = '<img src="' + banner + '" style="display: block; height: 200px;width: 200px">';
      $('.img_good').append(html)
      //图片预览
    })
  });

  $('.act_banner').click(function () {
    var myImage = _editor.getDialog("insertimage");
    myImage.open();
  });
  require(['modules/user/set'], function (set) {
    set.user_down('dropdown')
    set.user_set()
  });
</script>